﻿using CommunityToolkit.Mvvm.Messaging;
using HandyControl.Tools;
using Microsoft.Extensions.DependencyInjection;
using System.Collections.ObjectModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WpfDemo.Common;
using WpfDemo.ViewModel;

namespace WpfDemo.View
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow(MainWindowViewModel mainVm)
        {
            InitializeComponent();
            //this.DataContext = App.ServiceProvider.GetService<MainWindowViewModel>();
            this.DataContext = mainVm;
            WeakReferenceMessenger.Default.Register<string, string>(this, "ExpandMenuToken", DoExpandMenu);           
        }

        private ObservableCollection<ModuleGroup> moduleGroups;
        private ObservableCollection<TabModel> tabModels;
        private ObservableCollection<Modules> modules;
        private int tabIndex;

        private void DoExpandMenu(object recipient, string message)
        {
            if (this.menu.Width < 200)
            {
                //this.userName.Visibility = Visibility.Visible;
                Common.AnimationHelper.CreateWidthChangedAnimation(this.menu, 60, 200, new TimeSpan(0, 0, 0, 0, 300));
            }
            else
            {
               // this.userName.Visibility = Visibility.Collapsed;
                Common.AnimationHelper.CreateWidthChangedAnimation(this.menu, 200, 60, new TimeSpan(0, 0, 0, 0, 300));
            }


            //由于...
            var template = this.IC.ItemTemplateSelector;
            this.IC.ItemTemplateSelector = null;
            this.IC.ItemTemplateSelector = template;
        }

        private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                DragMove();
            }
        }
        private void MinWin_click(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }

        private void MaxWin_click(object sender, RoutedEventArgs e)
        {
            this.WindowState = (this.WindowState == WindowState.Maximized) ? WindowState.Normal : WindowState.Maximized;
        }

        private void CloseWin_click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            Button btn = (Button)sender;
            Grid gridtemp = (Grid)btn.Template.FindName("gridtemp", btn);
            Popup menuPop = (Popup)gridtemp.FindName("menuPop");
            menuPop.IsOpen = true;
        }
    }
}